package com.ssy.lingxi.member.merchant.controller.mobile;

import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.member.merchant.model.bo.MobileLoginBO;
import com.ssy.lingxi.member.merchant.model.vo.basic.request.PhoneVO;
import com.ssy.lingxi.member.merchant.model.vo.login.request.MobileLoginVO;
import com.ssy.lingxi.member.merchant.model.vo.login.request.MobilePhoneLoginVO;
import com.ssy.lingxi.member.merchant.model.vo.login.request.MobileShopTypeVO;
import com.ssy.lingxi.member.merchant.model.vo.login.request.MobileSwitchRoleVO;
import com.ssy.lingxi.member.merchant.model.vo.mobile.request.MobileMemberAuthCodeVO;
import com.ssy.lingxi.member.merchant.service.mobile.IMobileLoginService;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @menu App - 用户登录相关接口
 * @author 万宁
 * @version 2.0.0
 * @date 2020-12-03
 */
@RestController
@RequestMapping("/member/mobile")
public class MobileLoginController {
    @Resource
    private IMobileLoginService mobileLoginService;

    /**
     * 账号或手机号登录
     * @param headers Http头部信息
     * @param loginVO 接口参数
     * @return 登录用户信息
     */
    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public Wrapper<MobileLoginBO> accountOrPhoneLogin(@RequestHeader HttpHeaders headers, @RequestBody @Valid MobileLoginVO loginVO) {
        return mobileLoginService.accountOrPhoneLogin(headers, loginVO);
    }

    /**
     * 发送“手机号登录”的短信验证码
     * @param headers Http头部信息
     * @param phoneVO 接口参数
     * @return 发送结果
     */
    @RequestMapping(value = "/login/sendsms", method = RequestMethod.POST)
    public Wrapper<Void> sendPhoneLoginSmsCode(@RequestHeader HttpHeaders headers, @RequestBody @Valid PhoneVO phoneVO) {
        return mobileLoginService.sendPhoneLoginSmsCode(headers, phoneVO);
    }

    /**
     * 手机号登录
     * @param headers Http头部信息
     * @param loginVO 接口参数
     * @return 登录用户信息
     */
    @RequestMapping(value = "/login/phone", method = RequestMethod.POST)
    public Wrapper<MobileLoginBO> phoneLogin(@RequestHeader HttpHeaders headers, @RequestBody @Valid MobilePhoneLoginVO loginVO) {
        return mobileLoginService.phoneLogin(headers, loginVO);
    }

    /**
     * 根据token，重新获取登录用户信息
     * @param headers Http头部信息
     * @return 登录用户信息
     */
    @RequestMapping(value = "/login/reget", method = RequestMethod.GET)
    public Wrapper<MobileLoginBO> loginWithToken(@RequestHeader HttpHeaders headers, @Valid MobileShopTypeVO shopTypeVO) {
        return mobileLoginService.loginWithToken(headers, shopTypeVO);
    }

    /**
     * 会员登录后，选择角色
     * @param headers Http头部信息
     * @param roleVO 接口参数
     * @return 登录用户信息
     */
    @RequestMapping(value = "/login/role/switch", method = RequestMethod.POST)
    public Wrapper<MobileLoginBO> switchLoginRole(@RequestHeader HttpHeaders headers, @RequestBody @Valid MobileSwitchRoleVO roleVO) {
        return mobileLoginService.switchLoginRole(headers, roleVO);
    }

    /**
     * 业务平台 - 授权码确认登录
     * @param headers HttpHeaders信息
     * @param authCodeVO 接口参数
     * @return 登录结果
     */
    @RequestMapping(value = "/authCode/active", method = RequestMethod.POST)
    public Wrapper<Void> authCodeActive(@RequestHeader HttpHeaders headers, @RequestBody @Valid MobileMemberAuthCodeVO authCodeVO) {
        return mobileLoginService.authCodeActive(headers, authCodeVO);
    }
}
